package fr.babostesting.unit.touch
{
	import flash.display.StageQuality;
	import flash.ui.Multitouch;
	import flash.ui.MultitouchInputMode;
	import fr.babos.core.entries.Document;
	import fr.babos.graphic.components.base.StageWrapper;
	import fr.babos.graphic.components.bitmaps.AdvancedBitmap;
	import fr.babos.touch.delegate.IGestureTouchDelegate;
	import fr.babos.touch.emulator.GestureTouchEmulator;
	import fr.babos.touch.emulator.MouseToTouchEmulator;
	import fr.babos.touch.events.GestureTouchDragEvent;
	import fr.babos.touch.events.GestureTouchEvent;
	
	/**
	 * @author ZoulouX
	 */
	public class GestureTouchEmulatorTest extends Document implements IGestureTouchDelegate
	{
		protected var _emulator:GestureTouchEmulator;
		protected var _wrapper:StageWrapper;
		protected var _backBitmap:AdvancedBitmap;
		protected var _bloc:AdvancedBitmap;
		public function GestureTouchEmulatorTest ()
		{
			
		}
		
		
		override public function init ():void
		{
			if (Multitouch.supportsTouchEvents)
			{
				Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
			}
			else
			{
				MouseToTouchEmulator.emulate(stage, true);
			}
			
			stage.quality = StageQuality.LOW;
			
			_wrapper = new StageWrapper(stage);
			
			_backBitmap = new AdvancedBitmap(null, null, 1, 0xDEDEDE);
			_backBitmap.place(0, 0, 0, 0).into(_wrapper);
			
			
			_bloc = new AdvancedBitmap(null, null, 1, 0xFF0000);
			_bloc.center(0, 0).size(100, 100).into(_wrapper);
			
			_emulator = new GestureTouchEmulator(_bloc, this);
		}
		
		
		public function gestureTouchHandler (event:GestureTouchEvent):void
		{
			if (event is GestureTouchDragEvent)
			{
				var dragEvent:GestureTouchDragEvent = event as GestureTouchDragEvent;
				
				if (dragEvent.type == GestureTouchDragEvent.LOCK_DRAG)
					trace("v ------------------------------------------ v");
				
				trace(
						"drag", dragEvent.type,
						"vertical", dragEvent.isVertical, "horizontal", dragEvent.isHorizontal,
						"both", dragEvent.isBoth,
						"delta", dragEvent.xDelta, dragEvent.yDelta
					);
				
				_bloc.horizontalCenter += dragEvent.xDelta;
				_bloc.verticalCenter += dragEvent.yDelta;
				
				if (dragEvent.type == GestureTouchDragEvent.UNLOCK_DRAG)
					trace("^ ------------------------------------------ ^");
			}
			else
			{
				trace("other", event.type);
			}
		}
	}
}